<div class="layui-body-header">
  <h2>分会审核列表</h2>
</div>

<div class="layui-card-body">
  <div class="layui-fluid">
    <div class="layui-card">
          <div class="layui-card-header">
            <!-- <span>所有会员列表</span> -->
            <a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-primary" onclick="del()">
              <i class="layui-icon">&#xe640;</i>
              <span>批量删除</span>
            </a>
            <a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-primary" onclick="examine()">
              <i class="layui-icon">&#xe60a;</i>
              <span>审核</span>
            </a>
            <a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-primary" id="search_hash">
              <i class="layui-icon">&#xe615;</i>
            </a>
          </div>
          <div class="layui-card-body">
            <table id="demo_hash" lay-filter="test"></table>
            <script type="text/html" id="barDemo_hash">
              <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
              <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a> -->
              <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
          </div>
        </div>
      </div>
    </div>
      
      

<script type="text/html" id="search_tpl_hash">
  <form class="layui-form" action="">
    <div class="layui-form-item">
      <label class="layui-form-label">会员姓名</label>
      <div class="layui-input-block">
        <input type="text" name="MemberName" id="renming" placeholder="" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">所在地区</label>
      <div class="layui-input-block">
        <table class="layui-table fenhuiArea" lay-skin="nob">
          <tbody>
            <tr>
              <td>
                <select name="province" class="province" lay-verify="" lay-filter="provinces"> 
                      <option value="">省份</option>
                    </select> 
              </td>
              <td>
                <select name="city" class="city" lay-verify="" lay-filter="citys">
                  <option value="">城市</option>
                </select> 
              </td>
              <td>
                <select name="Area" class="Area" id="quyu" lay-verify="" lay-filter="Areas">
                  <option value="">区域</option>
                </select> 
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="formDemo_hash"><i class="layui-icon">&#xe615;</i> 搜索</button>
        <button type="reset" id="resets" class="layui-btn layui-btn-primary reset">重置</button>
      </div>
    </div>
  </form>
</script>

<script>
	let areaCode = '';
  let selectId = []
  layui.use(['table', 'sidebar', 'form'], function () {
    var layer = layui.layer,
      table = layui.table,
      sidebar = layui.sidebar,
      form = layui.form;
    //第一个实例
    table.render({
      method: 'post',
      id:'test',
      // size: 'sm',
      limit: 10,
      elem: '#demo_hash',
      height: 'full-235',
      url: 'https://xnsmb.xnsoft.net.cn/api/Filtrate_Xn_CircleMember', //数据接口
      page: true, //开启分页
      parseData: function(res){
        return {
          'code':0,
          'count':res.TotalCount,
          "data":res._Data
        };
      },
      where: {
        "Name": "",
        "AreaCode": "",
        "CircleCategoryId": 1,//1分 2商
        "CircleGuid": "",
        "IsAudit":0,
      },
      request: {
        pageName: 'CurrentPage' //页码的参数名称，默认：page
        ,limitName: 'PageSize' //每页数据量的参数名，默认：limit
      },
      cols: [
        [ //表头
          {
//          field: 'id',
//          title: 'ID',
//          width: 70,
            type: 'checkbox',
            sort: true,
            align: 'center',
          }, 
          {
            field: 'MemLoginId',
            title: '会员ID',
            align: 'center',
          },{
            field: 'Guid',
            title: 'Guid',
            align: 'center',
            hide:true
//          width: 200
          }, {
            field: 'MemberName',
            align: 'center',
            title: '会员名称',
//          width: 200
          }, {
            field: 'MemberMobile',
            title: '会员手机号',
            align: 'center',
//          width: 200
          }, {
            field: 'CircleName',
            title: '所加入的分会名称',
            align: 'center',
          }, {
            field: 'CreateTime',
            title: '申请时间',
            sort: true,
            align: 'center',
            templet:function (d) {
                  var a=d.CreateTime.split('T')
//                var c =a[1].split('.')
//                a = a[0]+' '+c[0]
									a = a[0]
                  return a
                }
          }
        ]
      ]
    });

    $('#search_hash').on('click', function () {
      var that = this;
      // console.log($('#search_tpl_hash').html());
      sidebar.render({
        elem: that,
        content: $('#search_tpl_hash').html(),
        title: '搜索',
        shade: true,
        // shadeClose:false,
        // direction: 'left'
        // dynamicRender: false,
        // url: 'views/member/all/search.html',
        width: '500px', //可以设置百分比和px
        done: function () {
          console.log('ccc');
          
			let re = document.querySelector(".reset");
			
			$("#resets").click(function(){
          	console.log(1)
          	areaCode = '';
          })


      takeArea();form.render();
      function takeArea(){
        let province = document.querySelector(".province");
        let city = document.querySelector(".city");
        let Areas = document.querySelector(".Area");
        let proArr = [];
        let ciArr = [];
        $.ajax({//异步请求返回给后台
            url:'https://xnsmb.xnsoft.net.cn/api/GetXn_DispatchRegion',
            type:'get',
            data:{FatherId:'0'},
            dataType:'json',
            beforeSend: function(request) {
			            
			            request.setRequestHeader("Authorization", 'bearer ' + localStorage.getItem("token"));
			        },
            success:function(data){
              //这里获取到数据执行显示
              proArr = [...data]
//              console.log("地址data",data)
              let p = document.createElement('option');
              p.value='';
              p.innerText="省份";
              data.forEach((el,index)=>{
//              let op = document.createElement('option');
//              op.value = el.ID+'-'+el.Code;
//              op.innerText = el.Name;
//              province.appendChild(op)
                $(".province").append("<option value='"+el.ID+"'>"+el.Name+"</option>");
              })
              form.render();
            }
            
          });
          
          form.on('select(provinces)', function(data){
          	$(".city").empty();
            cityCode = data;
            console.log(1,data.value)
            if(data.value==""){
	      				areaCode="";
	      			}
            proArr.forEach((el,index)=>{
		  				if(el.ID==data.value){
		  					areaCode=el.Code;
		  				}
		  			})
            		
		  			console.log("areaCode",areaCode);
      //      console.log("seFrist",seFrist)
//            console.log(data.value);
            $.ajax({//异步请求返回给后台
                  url:'https://xnsmb.xnsoft.net.cn/api/GetXn_DispatchRegion',
                  type:'get',
                  data:{FatherId:data.value.split('-')[0]},
                  dataType:'json',
                  beforeSend: function(request) {
			            
			            request.setRequestHeader("Authorization", 'bearer ' + localStorage.getItem("token"));
			        },
                  success:function(data){
                    ciArr = [...data];
                    //这里获取到数据执行显示
                    console.log(data)
      //              console.log("secJobs",secJobs.length)
      //              secJobs="";
//                  $(".city").empty();
//                  let p = document.createElement('option');
//                  p.value = "";
//                  p.innerText = "城市";
//                  city.appendChild(p)
                    $(".city").append("<option value=''>城市</option>");
                    data.forEach((el,index)=>{
//                    let op = document.createElement('option');
//                    op.value = el.ID+'-'+el.Code;
//                    op.innerText = el.Name;
//    //                op.id = el.Id;
//                    city.appendChild(op)
                      
                      $(".city").append("<option value='"+el.ID+"'>"+el.Name+"</option>");
                    })
                    form.render();
                    
                  }
                  
                });
          });   
          
          form.on('select(citys)', function(data){
          	$(".Area").empty();
          	let _city = data.value;
            console.log(data)
            if(data.value==""){
  				areaCode=areaCode.substr(0,3);
  			}
//            AreaCode = data;
      //      console.log("seFrist",seFrist)
//            console.log(data.value);
            $.ajax({//异步请求返回给后台
                  url:'https://xnsmb.xnsoft.net.cn/api/GetXn_DispatchRegion',
                  type:'get',
                  data:{FatherId:data.value.split('-')[0]},
                  dataType:'json',
                  beforeSend: function(request) {
			            
			            request.setRequestHeader("Authorization", 'bearer ' + localStorage.getItem("token"));
			        },
                  success:function(data){
                    ciArr.forEach((el,index)=>{
					    		  	if(el.ID==_city){
					    		  		areaCode=el.Code
					    		  	}
					    		  })
                    //这里获取到数据执行显示
                    console.log(data)
      //              console.log("secJobs",secJobs.length)
      //              secJobs="";
//                  $(".Area").empty();
//                  let p = document.createElement('option');
//                  p.value = "";
//                  p.innerText = "区域";
//                  Areas.appendChild(p)
                    $(".Area").append("<option value=''>区域</option>");
                    data.forEach((el,index)=>{
//                    let op = document.createElement('option');
//                    op.value = el.Code;
//                    op.innerText = el.Name;
//    //                op.id = el.Id;
//                    Areas.appendChild(op)
                      $("#quyu").append("<option value='"+el.Code+"'>"+el.Name+"</option>");
                    })
                    form.render();
                    
                  }
                  
                });
          }); 
          
             form.on('select(Areas)', function(data){
               if(data.value!=""){
							areaCode = $("#quyu option:selected").val();
//							areas = $(".province option:selected").text()+$(".city option:selected").text()+$(".Area option:selected").text();
						}else{
							areaCode=areaCode.substr(0,6);
						}
            
                  console.log("areaCode",areaCode);
//                console.log("areas",areas)
             })
          
      }



          //监听提交
          form.on('submit(formDemo_hash)', function (data) {
            console.log(data.field)
            var areaCode = ""
            if (data.field.Area != "") {
              areaCode = data.field.Area
            }else if (data.field.city != "") {
              areaCode = data.field.city.split('-')[1]
            }else {
              areaCode = data.field.province.split('-')[1]
            }
            console.log(areaCode)
            // layer.msg(JSON.stringify(data.field));
            table.reload('test', {
              where: {
                Name:$("#renming").val(),
                AreaCode:areaCode
              }
            });
            return false;
          });
        }
      });
    });



    table.on('checkbox(test)',function (obj) {
      var checkStatus = table.checkStatus('test'); //idTest 即为基础参数 id 对应的值
      selectId = []
      for(var i = 0 ; i < checkStatus.data.length ; i++){
        selectId.push(checkStatus.data[i].Guid)
      }
    })

  });
    //删除
    function del(){
      if (selectId.length == 0) {
        alert('请先选择需要删除项')
        return false
      }
      layui.use('form', function(){
      	
      	let index = layer.confirm("确认删除？",function(){
      		DBHelper.Delete('Admin_Xn_CircleMember',selectId,function (res) {
                
              },function(res){
								location.href = window.location.href
                layer.close(index);
              }) 
      	})
      	
//      layer.open({
//        content: '确认删除？',
//        yes: function(index, layero){
//            DBHelper.Delete('Admin_Xn_CircleMember',selectId,function (res) {
//              location.href = window.location.href
//            },function(res){
//
//            }) 
//        }
//      })
      });
    }

    //审核
    function examine(){
      if (selectId.length == 0) {
        alert('请先选择需要审核项')
        return false
      }
      DBHelper.PostArr('IsAudit_Xn_CircleMember',selectId,function(res){
      	let index = layer.alert("审核通过",function(){
      		location.href = window.location.href
      		layer.close(index)
      	})
        
      },function(res){
        console.log(res)
        alert('审核失败')
      })
    }
    
    //强制刷新
//  var a = window.name
//  if(a == ''){
//  	window.name = "reloded"
//  	location.reload()
//  }else{
//  	window.name=""
//  }
</script>





	<style scoped>
      	.title{
      		margin-left: 30px;
      		margin-top: 30px;
      	}
      	.checkBtn{
      		border-radius: 5px;
      		width: 100px;
      	}
      	.listBtns{
      		display: flex;
      		justify-content: space-between;
      		width: 100%;
      	}
      	.listBtn{
      		border-radius: 5px;
      	}
      	.check-table tr>th{
      		text-align: center;
      	}
      	.check-table tr>td{
      		text-align: center;	
      	}
      	
      </style>
      
